package util;

import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class ListUtil {

	public ListUtil() {
	}

	/**
	 * 刘柱栋    2013-4-6
	 * @param args
	 */
	public static void main(String[] args) {
		List<Integer> list1 = Arrays.asList(1,2,3,4);
		List<Integer> list2 = Arrays.asList(4,3,2,1);
		
//		Collections.sort(list1);
//		Collections.sort(list2);
		
		System.out.println(list1);
		System.out.println(list2);
		
//		boolean flag = compara(list1, list2);
		boolean flag = equals(list1, list2);
		System.out.println(flag);
		
		
		double d = 1.05;
		double q = 2.01;
		d = d + q;
		System.out.println(d);
		
	}
	/**
	 * 操作：实现两个List元素是否相同的比较.<br>
	 * 备注：此处不能实现list中重复元素的比较.<br>
	 * 刘柱栋    2013-4-6
	 * @param listOne
	 * @param listTwo
	 * @return
	 * @version 1.0
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static boolean equals(List listOne , List listTwo){
		if(listOne == null){
			return false;
		}else if(listTwo == null){
			return false;
		}else if(listOne.size() != listTwo.size()){
			return false;
		}else{
			for(Iterator<Object> iter = listOne.iterator(); iter.hasNext() ; ){
				Object o = iter.next();
				if(!listTwo.contains(o)){
					return false;
				}
			}
		}
		return true;
	}
	
	/**
	 * 操作：实现两个list元素是否相同的比较；list里的元素必须是可比较的.<br>
	 * 刘柱栋    2013-4-6
	 * @param listOne
	 * @param listTwo
	 * @return
	 * @version 1.0
	 */
	public static <T extends Comparable<T>> boolean compara(List<T> listOne , List<T> listTwo){
		if(listOne == null){
			return false;
		}else if(listTwo == null){
			return false;
		}else if(listOne.size() != listTwo.size()){
			return false;
		}else{
			Collections.sort(listOne);
			Collections.sort(listTwo);	
			for(int i = 0 , size = listOne.size(); i < size ; i++){
				if(!listOne.get(i).equals(listTwo.get(i))){
					return false;
				}
			}
		}
			
		return true;
	}

}
